﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Final
{
    public partial class AddForm : Form
    {
        public AddForm()
        {
            InitializeComponent();
           
        }


        //添加文章添加按钮
        private void button1_Click(object sender, EventArgs e)
        {
            var title = TitleText.Text;
            var author = AuthorText.Text;
            var sql1 = string.Format("select * from Articles where Title like '%{0}%' and Author like '%{1}%'", title, author);
            var d = DBhelp.GetDataTable(sql1);
            if (title=="" || author=="")
            {
                MessageBox.Show("请输入你需要添加的文章或作者");
            }
            else
            {
                if (d.Rows.Count == 1)
                {
                    MessageBox.Show("已存在该文章");
                }
                else
                {
                    var sql = string.Format("insert into Articles(Title,Author) values ('{0}','{1}')", title, author);
                    DBhelp.UpdateDeleteAdd(sql);
                    this.Close();
                }
            }
            
            
            

        }


        //添加文章返回按钮
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            DataGridView dataGridView = new DataGridView();
            var sql = "select * from Articles";
            var dt = DBhelp.GetDataTable(sql);
            dataGridView.DataSource = dt;
        }
    }
}
